package org.bot.plugin.web.event;

import com.alibaba.fastjson.JSONObject;
import org.bot.api.event.DataStorage;
import org.bot.api.event.EventName;
import org.bot.api.event.Events;
import org.bot.api.flow.FlowNode;
import org.bot.http.client.HttpTool;
import org.bot.plugin.web.util.CookieBuild;
import org.bot.plugin.web.util.WebApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@EventName("站内GET请求")
public class WebSiteHttpGet implements Events {

    @Autowired
    WebApi webApi;

    @Override
    public Object exec(FlowNode note, DataStorage data) {
        String arg = note.getArg();
        if (arg == null) {
            arg = data.get(note.getDataIndex()).toString();
        }
        return HttpTool.doGet(arg,
                CookieBuild.build(webApi.getWebDriver(note)));
    }

}
